! (Logical NOT)

The logical NOT operator is an inverter which is used to return a value of true or false, depending on the value of the operand. If the evaluated operand is true, then a value of false will be returned. If the evaluated operand is false, then a value of true will be returned. If the evaluated operand is of a data type other than the boolean type, an attempt is made to convert the operand to a boolean value before evaluating the operand.

syntax:

! operand

EXAMPLE

variableOne = new String("1");

variableTwo = ! variableOne;

document.write("variableOne evaluates to " + variableOne);

document.write("variableTwo evaluates to " + variableTwo);

This example illustrates the use of the logical NOT operator nicely. Think of the logical NOT operator as an inverter - true will be switched to false, and false to true. Simply put, variableOne is loaded with the string value "1", while variableTwo is loaded with the inverted value of variableOne. Since an attempt is made to convert any data type other than a boolean value to a true or false (boolean) value, the string value of variableOne will be converted to the boolean "true", or "1". The inverted value for variableTwo, then, is "false" or "0".